# -*- coding: utf-8 -*-
# @project: huawang-api20230914
# @file： mainPage.py
# @Time：2023/8/29 10:57
# @Author：liaogan
import logging

from common.commin.commin import click_element, get_elelment
from data.yk_names import Spel, mainPage
from po.jinhua.ht.jinhua_ht_main.jinhua_base import JHBase
from po.yk.ht.ProductManagrmentpage import CommdityManagrmentpage
from po.yk.ht.ProductManagrmentpage import CommdityManagrmentpage
from po.yk.ht.CoponPage import AddCoponPage
from common.log.log import log

class MainPage(JHBase):
    """
    功能
        1. 跳转到添加商品页
        2. 跳转到商品列表页
    """

    # 添加商品页面
    def goto_addproductpage(self):
        click_element(self.driver, mainPage.menu_productmanage())
        click_element(self.driver, mainPage.submenu_menuproduct())
        # 推荐正向返回其他页面，反向不建议，不要滥用
        # ---> 页面类 到底如何划分？
        return CommdityManagrmentpage()

    # 去商品列表页面
    def goto_productlistpage(self):
        # self.click_element(self.menu_productmanage)
        click_element(self.driver, mainPage.menu_productmanage())
        return CommdityManagrmentpage()

    # 去电子优惠券界面
    def goto_coponn(self):
        sel = get_elelment(self.driver, mainPage.menu_coupon1())
        open_or_not = sel.get_attribute('class')  # “用户” 菜单是否展开
        log.info(f'点击之前的class属性{sel.get_attribute("class")}')
        if 'is-opened' not in open_or_not:
            sel.click()
            log.info(f'点击之后的class属性{sel.get_attribute("class")}')
        click_element(self.driver, mainPage.submenu_newcoupon())
        return AddCoponPage()



